# 使用python处理csv数据
# id,name,chinese,english,math
"""
1,张三，85，90，88
2,李四，78，23，42
3，王五，87，34，15

 (1) 求取数据的行数
 (2) 求取并打印每位同学的平均成绩
 (3) 求取并打印平均成绩前三名的学生信息
"""

with open("./data/scores.txt","r",encoding="utf-8") as f:
    # f,read()
    f.readline()
    scores=[]
    data=f.readlines()
    print(len(data))

    # round(number, ndigits) 四舍五入保留 ndigits 位小数

    for i in data:
        print(round(sum(map(int,i.strip().split(',')[2:]))/3,1))
        # print(f"{sum(map(int,i.strip().split(',')[2:]))/3:.1f}")
        scores.append(round(sum(map(int,i.strip().split(',')[2:]))/3,1))
        # scores.append(sum(map(int,i.strip().split(',')[2:]))/3)
    print(scores)
    for _ in range(0,3):
        temp=max(scores)
        print(temp)
        # print(f"{temp:.1f}")
        scores.remove(temp)



# with open("./data/scores.txt", "r", encoding='utf-8') as f:
#     # 跳过表头
#     f.readline()
#     data = f.readlines()
#
#     # (1) 求取数据的行数
#     print(f"数据行数: {len(data)}")
#
#     scores = []
#     student_info = []
#
#     print("\n(2) 每位同学的平均成绩:")
#     for line in data:
#         # 替换中文逗号为英文逗号，并分割
#         items = line.strip().replace('，', ',').split(',')
#         # 提取成绩部分并转换为整数
#         grades = list(map(int, items[2:]))
#         average = sum(grades) / 3
#         scores.append(average)
#         student_info.append((items[1], average, items[2:]))
#         print(f"{items[1]}的平均成绩: {average:.2f}")
#
#     # (3) 平均成绩前三名的学生信息
#     print("\n(3) 平均成绩前三名的学生:")
#     # 将学生信息和成绩组合并排序
#     ranked_students = sorted(zip(scores, student_info), reverse=True)
#     for i, (score, info) in enumerate(ranked_students[:3], 1):
#         name, avg, grades = info
#         print(f"第{i}名: {name}, 平均成绩: {avg:.2f}, "
#               f"语文: {grades[0]}, 英语: {grades[1]}, 数学: {grades[2]}")


